<template>
	<view>
		<button type="default" @click="upload">上传</button>
		<view ref="input" class="input">123</view>
	</view>
</template>

<script>
	export default {
		onReady() {
			this.$nextTick(() => {
				var input = document.createElement('input')
				input.type = 'file';
				input.id = "fileuplaod";
				input.onchange = (e) => {
					console.log(e);
				}
				setTimeout(() => {
					this.$refs.input.$el.appendChild(input)
				}, 1000)
			})
		},
		methods: {
			upload() {
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						let url = this.vuex_config.adminPath
						// #ifdef APP-PLUS
						url = this.vuex_config.baseUrl
						// #endif
						uni.uploadFile({
							url: url + '/common/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							header: {
								'Authorization': this.vuex_token
							},
							name: 'file',
							success: (uploadFileRes) => {
								console.log(JSON.stringify(uploadFileRes));
							}
						});
					}
				});
			}
		}
	}
</script>

<style>
</style>
